package org.aaron.demos;

import org.aaron.demos.utils.DownloadHelper;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class FileDownLoadActivity extends Activity {
	private Button download_btn, download2sdcard_btn;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.filedownloadlayout);
		initActivity();
	}

	private void initActivity() {
		download_btn = (Button) this.findViewById(R.id.download_btn);
		download2sdcard_btn = (Button) this.findViewById(R.id.download2sdcard_btn);
		download_btn.setOnClickListener(new DownloadClickListener());
		download2sdcard_btn.setOnClickListener(new Download2SdcardClickListener());
	}

	class DownloadClickListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			DownloadHelper downloadHelper = new DownloadHelper();
			String text=downloadHelper.downloadFile2String("http://192.168.16.222:8080/Example_Web/voa/1.qrc");
			Log.i("file2test", text);
		}
	}

	class Download2SdcardClickListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			DownloadHelper downloadHelper = new DownloadHelper();
			int result=downloadHelper.downloadFile2Sd("http://192.168.16.222:8080/Example_Web/voa/1.mp3", "voa/", "1.mp3");
			Log.i("download result:", String.valueOf(result));
		}
	}
}
